//
//  NavigationController.m
//  DanTang
//
//  Created by honeyrr on 2017/9/7.
//  Copyright © 2017年 honeyrr. All rights reserved.
//

#import "KANavigationController.h"

@interface KANavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation KANavigationController


+ (void)initialize
{
    //自定义navbar，根据使用当前nav类自定义navbar
    UINavigationBar *nb = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[KANavigationController class]]];
    //设置导航条背景色
    nb.barTintColor = KANavTabColor;
    
    //设置导航条字体颜色和大小
    NSDictionary *dict = @{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont systemFontOfSize:16] };
    [nb setTitleTextAttributes:dict];
    [nb setTintColor:[UIColor whiteColor]];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //自定义导航栏返回的失效问题
    self.interactivePopGestureRecognizer.delegate = self;
}

//拦截push
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    //判断push进来的界面是否为第一个
    if(self.childViewControllers.count > 0){
        //push后隐藏底部栏
        viewController.hidesBottomBarWhenPushed = YES;
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"checkUserType_backward_9x15_"] style:UIBarButtonItemStylePlain target:self action:@selector(navigationBarClick)];
    } else {
        
    }
    [super pushViewController:viewController animated:YES];
}
//返回事件
-(void)navigationBarClick
{
    [self popViewControllerAnimated:YES];
}

//手势的代理方法
-(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    return self.childViewControllers.count > 1;
}

//
-(UIStatusBarStyle)preferredStatusBarStyle
{
    return UIStatusBarStyleLightContent;
}

@end
